<template>
  <div class="user-info">
    <el-dropdown>
      <div class="user-info-menu">
        <el-avatar
          src="https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png"
          size="small"
        ></el-avatar>
        <span class="nick-name">{{ nickName }}</span>
      </div>
      <template #dropdown>
        <el-dropdown-menu>
          <el-dropdown-item @click="exitLogOut">退出登录</el-dropdown-item>
          <el-dropdown-item divided></el-dropdown-item>
          <el-dropdown-item>用户信息</el-dropdown-item>
          <el-dropdown-item>系统管理</el-dropdown-item>
        </el-dropdown-menu>
      </template>
    </el-dropdown>
  </div>
</template>

<script lang="ts">
import { defineComponent, computed } from 'vue'
import { useRouter } from 'vue-router'
import { useStore } from 'vuex'
import localcache from '@/utils/cache'
import ToastUtil from '@/utils/toast'
export default defineComponent({
  setup(props) {
    const store = useStore()
    const router = useRouter()
    const nickName = computed(() => {
      return store.state.login.userInfo.name
    })
    //1:退出登录
    const exitLogOut = () => {
      ToastUtil.alert({
        message: '您确定要退出登录吗?',
        showCancelButton: true,
        cancelButtonText: '取消',
        confirmButtonText: '退出登录'
      }).then((state: boolean) => {
        if (state) {
          localcache.clearCache()
          router.replace('/login')
        }
      })
    }

    return { nickName, exitLogOut }
  }
})
</script>

<style scoped lang="less">
.user-info {
  .user-info-menu {
    display: flex;
    align-items: center;
    cursor: pointer;
    .nick-name {
      margin-left: 2px;
    }
  }
}
</style>
